package org.helgoboss.jintellitype;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.melloware.jintellitype.JIntellitype;
import java.io.*;

public class JIntellitypeActivator implements BundleActivator {
    public void start(BundleContext context) {
        JIntellitype.getInstance();
    }
    
    public void stop(BundleContext context) {
        JIntellitype.getInstance().cleanUp();
    }
	
	private String extractDll(String dllName, BundleContext bundleContext) {
		try {
			String tmpDir = System.getProperty("java.io.tmpdir");
			String filePath = tmpDir + "/" + dllName;
			String jarPath = "com/melloware/jintellitype/" + dllName;
			File file = new File(filePath);
			if (file.exists()) {
			   file.delete();
			}
			InputStream is = null;
			OutputStream os = null;
			try {
			   is = bundleContext.getBundle().getResource(jarPath).openStream();
			   os = new FileOutputStream(filePath);
			   byte[] buffer = new byte[8192];
			   int bytesRead;
			   while ((bytesRead = is.read(buffer)) != -1) {
				  os.write(buffer, 0, bytesRead);
			   }
			} finally {
			   if (is != null) {
				  is.close();
			   }
			   if (os != null) {
				  os.close();
			   }
			}
			return filePath;
		} catch (IOException ex) {
			throw new RuntimeException(ex);
		}
	}
}